package com.helloworld.controller;

import com.helloworld.service.RoleService;
import com.helloworld.vo.HttpResponse;
import com.helloworld.vo.Role.RoleAddReq;
import com.helloworld.vo.Role.RoleListReq;
import com.helloworld.vo.Role.RoleUpdateReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleservice;

    @GetMapping({"/Info"})
    public HttpResponse queryRoleById(Integer id){
        return HttpResponse.suc(roleservice.queryRoleById(id));
    }

    @GetMapping({"/list"})
    public HttpResponse queryRoleList(RoleListReq req){
        return HttpResponse.suc(roleservice.queryRoleList(req.getNameLike()));
    }

    @PostMapping("/add")
    public HttpResponse addRole(@RequestBody RoleAddReq req){
        Integer id = roleservice.addRole(req);
        return HttpResponse.suc(roleservice.queryRoleById(id));
    }

    @PostMapping({"/update"})
    public HttpResponse updateRole(@RequestBody RoleUpdateReq req){
        roleservice.updateRole(req);
        return HttpResponse.suc(roleservice.queryRoleById(req.getId()));
    }

    @PostMapping({"/delete"})
    public HttpResponse deleteRole(Integer id){
        roleservice.deleteRole(id);
        return HttpResponse.suc(null);
    }
}
